package com.luban.service;

import com.luban.dao.UserMapper;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.stereotype.Component;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @Author: lijunwei
 * @Time: 2021/2/15 17:11
 */
@Component
public class UserFactoryBean implements FactoryBean {

	@Override
	public Object getObject() throws Exception {
		Object o = Proxy.newProxyInstance(UserFactoryBean.class.getClassLoader(), new Class[]{UserMapper.class}, new InvocationHandler() {
			@Override
			public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
				return method.invoke(proxy, args);
			}
		});
		return o;
	}

	@Override
	public Class<?> getObjectType() {
		return UserMapper.class;
	}
}
